package smartcase.base.auth;

import com.google.common.base.Strings;
import javax.servlet.http.HttpServletRequest;

public interface AbstractHeaderCredentialFunction extends AbstractCredentialFunction {

  String getHeaderKey();

  default Credential verify(HttpServletRequest request) {
    String headerValue = request.getHeader(getHeaderKey());
    if (Strings.isNullOrEmpty(headerValue)) return Credential.INVALID_CREDENTIAL;
    return mapHeaderValueToCredential(request, headerValue);
  }

  Credential mapHeaderValueToCredential(
          HttpServletRequest request, String headerValue);
}
